package com.lightsh.coverflow;

import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

public class MainActivity extends Activity {
    
	private CoverFlowGallery mCoverFlow;
	private CoverFlowAdapter mAdapter;
	private ArrayList<Bitmap> mBitmaps;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mCoverFlow = (CoverFlowGallery)findViewById(R.id.coverFlow);
        if(mAdapter == null){
        	mBitmaps = new ArrayList<Bitmap>();
        	mAdapter = new CoverFlowAdapter(mBitmaps, this);
        	mCoverFlow.setAdapter(mAdapter);
        }
        
        mCoverFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
			}
		});
        
        initBitmap();
    }
    
    private void initBitmap(){
    	
    	File file = new File("/sdcard/Photo/wallpaper");
    	int count = 0;
    	if(file.exists() && file.isDirectory()){
    		File[] imageFiles = file.listFiles();
    		for(File imageFile : imageFiles){
    			if(imageFile.isFile() && 
    					(imageFile.getAbsolutePath().toLowerCase().endsWith(".png") 
    							|| imageFile.getAbsolutePath().toLowerCase().endsWith(".jpg"))){
    				++count;
    				if(count > 10){
    					break;
    				}
    				mBitmaps.add(ImageUtility.scallBitmap(BitmapFactory.decodeFile(imageFile.getAbsolutePath()), 0.5f));
    			}
    		}
    	}
    	mAdapter.notifyDataSetChanged();
    }
}